home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / ClassFree_src.lha / ClassFree_src / CFfuelgiclass / class_lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-25  |  2.5 KB  |  123 lines

  1. /* Library replacement routines */
  2.  
  3. #include <exec/libraries.h>
  4. #include <proto/exec.h>
  5. #include <intuition/classes.h>
  6. #include <dos/dos.h>
  7. #include "class.h"
  8.  
  9. #pragma libbase classbase  /* So StormCs linker knows the libbase size.. */
  10.  
  11. extern struct ExecBase *SysBase;
  12. struct Library *IntuitionBase;
  13. struct Library *UtilityBase;
  14. struct Library *GfxBase;
  15. struct Library *TxtiBase;
  16. #ifdef DEBUG
  17.  #include "debug_protos.h"
  18.  APTR console;
  19. #endif
  20.  
  21. BPTR LibExpunge();
  22. BOOL openlibs(void);
  23. void closelibs(void);
  24.  
  25. struct classbase *LibInit(
  26.         register __d0 struct classbase *base,
  27.         register __a0 BPTR seglist,
  28.         register __a6 APTR sysbase)
  29. {
  30.   base->seglist = seglist;
  31.   SysBase = sysbase;
  32.   if(openlibs()) return(base);
  33.   return(NULL);
  34. }
  35.  
  36. struct Library *LibOpen(register __a6 struct classbase *base)
  37. {
  38.   if(!(base->library.lib_OpenCnt)) initclass(base);
  39.   base->library.lib_Flags &= ~LIBF_DELEXP;
  40.   base->library.lib_OpenCnt++;
  41.   return((struct Library *)base);
  42. }
  43.  
  44. BPTR LibClose(register __a6 struct classbase *base)
  45. {
  46.   base->library.lib_OpenCnt--;
  47.   if(!base->library.lib_OpenCnt)
  48.     if(base->library.lib_Flags&LIBF_DELEXP) return(LibExpunge());
  49.   return(NULL);
  50. }
  51.  
  52. BPTR LibExpunge(register __a6 struct classbase *base)
  53. {
  54.   BPTR result;
  55.   UBYTE *libmem;
  56.   LONG libsize;
  57.  
  58.   if(base->library.lib_OpenCnt)
  59.   {
  60.     base->library.lib_Flags |= LIBF_DELEXP;
  61.     return(NULL)
  62.   }
  63.   else
  64.   {
  65.     result = base->seglist;
  66.     Remove((struct Node *)base);
  67.     closelibs();
  68.     removeclass(base);
  69.     libmem = (UBYTE *)base;
  70.     libsize = base->library.lib_NegSize;
  71.     libmem -= libsize;
  72.     libsize += base->library.lib_PosSize;
  73.     FreeMem(libmem,libsize);
  74.     return(result);
  75.   }
  76. }
  77.  
  78. ULONG LibNull(void)
  79. {
  80.   return(NULL);
  81. }
  82.  
  83. BOOL openlibs(void)
  84. {
  85.   IntuitionBase = OpenLibrary("intuition.library",37);
  86.   UtilityBase = OpenLibrary("utility.library",37);
  87.   GfxBase = OpenLibrary("graphics.library",37);
  88.   if(!(TxtiBase = OpenLibrary("CFtext.image",0)))
  89.   {
  90.     TxtiBase = OpenLibrary("Images/CFtext.image",0);
  91.   }
  92. #ifdef DEBUG
  93.   console = DLopencon();
  94. #endif
  95.   if(IntuitionBase&&UtilityBase&&GfxBase&&TxtiBase) return(TRUE);
  96.   closelibs();
  97.   return(FALSE);
  98. }
  99.  
  100. void closelibs(void)
  101. {
  102. #ifdef DEBUG
  103.   DLclosecon(console);
  104. #endif
  105.   CloseLibrary(TxtiBase);
  106.   CloseLibrary(GfxBase);
  107.   CloseLibrary(UtilityBase);
  108.   CloseLibrary(IntuitionBase);
  109. }
  110.  
  111. /* This function converts register-parameter hook calling
  112.  * convention into standard C conventions.
  113.  */
  114. ULONG hookEntry(
  115.     register __a0 struct Hook *h,
  116.     register __a2 VOID *o,
  117.     register __a1 VOID *msg)
  118. {
  119.     return ((*h->h_SubEntry)(h, o, msg));
  120. }
  121.  
  122.  
  123.